package main

import "fmt"

func main() {
	arr := []int{1, 4, 2, 5, 3}
	l := 3
	fmt.Println(countSum(arr, l))
}

//#link: https://leetcode-cn.com/problems/sum-of-all-odd-length-subarrays/
func sumOddLengthSubarrays(arr []int) (ans int) {
	for i := 1; i <= len(arr); i = 2*i + 1 {
		ans += countSum(arr, i)
	}
	return ans
}

func countSum(arr []int, l int) (ans int) {
	for i := 0; i <= len(arr)-l; i++ {
		for j := i; j < i+l; j++ {
			ans += arr[j]
		}
	}
	return ans
}
